package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.ModifyOfRegistPassWordModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.PwdModifyContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Description:
 * Created by FHW
 * on 2017/4/1
 */

public class PwdModifyPresenter extends BasePresenter implements PwdModifyContract.Presenter {

    private PwdModifyContract.View view;
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil rsaJsonUtil;

    @Inject
    public PwdModifyPresenter(PwdModifyContract.View view) {
        this.view = view;
    }

    @Override
    public void getModifyOfRegistPassWord(String SalesID, String Mobile, String PassWord, String Type, String Code, String OldPassWord) {
        rsaJsonUtil.put("SalesID", SalesID);
        rsaJsonUtil.put("Mobile", Mobile);
        rsaJsonUtil.put("PassWord", PassWord);
        rsaJsonUtil.put("Type", Type);
        if (!Code.isEmpty()) {
            rsaJsonUtil.put("Code", Code);
        }
        if (!OldPassWord.isEmpty()) {
            rsaJsonUtil.put("OldPassWord", OldPassWord);
        }
        view.showLoadingDialog(mContext.getString(R.string.text_loading));
        ApiServiceHelper.
                appointThreadNormal(apiService.getModifyOfRegistPassWord(rsaJsonUtil.getRsaParams())).
                subscribe(new Observer<ModifyOfRegistPassWordModel>() {
                    @Override
                    public void onCompleted() {
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        HttpExcUtil.printError(e);
                        view.closeLoadingDialog();
                    }

                    @Override
                    public void onNext(ModifyOfRegistPassWordModel modifyOfRegistPassWordModel) {
                        view.loadSucModifyOfRegist(modifyOfRegistPassWordModel.getData());
                    }
                });

    }
}
